﻿@page
@using System.Runtime.InteropServices
@using System.IO
@using System.Diagnostics
@model IndexModel
@{
    ViewData["Title"] = "Home page";
    var process = Process.GetCurrentProcess();
}

<div class="text-center">
    <h1 class="display-4">Welcome to .NET Core</h1>

    <h5>Environment</h5>
    <p>@RuntimeInformation.FrameworkDescription</p>
    <p>@RuntimeInformation.OSDescription</p>
</div>

<div>
    <h5 class="text-center">Metrics</h5>
    <table width="500" align="center" class="table-striped table-hover">
        <tr>
            <td>Containerized</td>
            <td>@(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") is object ? "true" : "false")</td>
        </tr>
        <tr>
            <td>CPU cores</td>
            <td>@Environment.ProcessorCount</td>
        </tr>
    @if (RuntimeInformation.OSDescription.StartsWith("Linux") && Directory.Exists("/sys/fs/cgroup/memory"))
    {
        <tr>
            <td>cgroup memory usage</td>
            <td>@System.IO.File.ReadAllLines("/sys/fs/cgroup/memory/memory.usage_in_bytes")[0]</td>
        </tr>
    }
        <tr>
            <td>Memory, current usage (bytes)</td>
            <td>@process.WorkingSet64</td>
        </tr>
        <tr>
            <td>Memory, max available (bytes)</td>
            <td>@process.MaxWorkingSet</td>
        </tr>    
    </table>
</div>
